﻿package mortal.game.view.task
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gLinkText.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.game.view.task.data.*;
    import mortal.game.view.task.view.*;
    import mortal.game.view.task.view.track.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class TaskTrackForNewPlayer extends View
    {
        private var _bodySprite:GSprite;
        private var _bg:ScaleBitmap;
        private var _txtChapter:GTextFiled;
        private var _moveBtn:GLoadedButton;
        private var _btnShowTrack:BtnShowTrackModule;
        private var _reward:ShopSellItem;
        private var _bmpChapter:GImageBitmap;
        private var _jindu:GBitmap;
        private var _txtJindu:GTextFiled;
        private var _line:ScaleBitmap;
        private var _txtName:GTextFiled;
        private var _txtDes:GTextFiled;
        private var _link:GLinkText;
        private var _link2:GLinkText;
        private var _link3:GLinkText;
        private var _btn:GLabelButton;
        private var sx:int = 24;
        private var sy:int = 28;
        private var _resGot:Boolean = false;
        private var _taskInfo:TaskInfo;
        private var _dragRect:Rectangle;
        private var _line2:ScaleBitmap;
        private var _subLines:Array;
        private var _light:ScaleBitmap;
        private var _guideFlybootArrow:TaskGuideArrow;
        private var _showingNum:int = -1;

        public function TaskTrackForNewPlayer(param1:ILayer = null)
        {
            this._dragRect = new Rectangle();
            this._subLines = [];
            super.layer = LayerManager.uiLayer;
            return;
        }// end function

        public function set sublines(param1:Array) : void
        {
            var _loc_3:TaskInfo = null;
            var _loc_4:GLinkText = null;
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                _loc_4 = this._subLines[_loc_2];
                if (_loc_4 == null)
                {
                    _loc_4 = UICompomentPool.getUICompoment(GLinkText);
                    this._subLines.push(_loc_4);
                }
                _loc_4.widthConst = 194;
                _loc_4.setLinkText(Cache.instance.task.getCurLinkTextDatas(_loc_3)[0]);
                this._bodySprite.addChild(_loc_4);
                _loc_2++;
            }
            DisplayUtil.delNotUse(this._subLines, _loc_2);
            return;
        }// end function

        public function hideTrackExceptBtn(param1:Boolean) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (param1)
            {
                this._btnShowTrack.close();
            }
            else
            {
                this._btnShowTrack.open();
            }
            this.showHideTrackHandler(null);
            return;
        }// end function

        public function set taskInfo(param1:TaskInfo) : void
        {
            this._taskInfo = param1;
            this.updateTaskInfoView();
            return;
        }// end function

        private function updateTaskInfoView() : void
        {
            if (this._taskInfo == null)
            {
                return;
            }
            this._txtName.text = this._taskInfo.stask.name;
            var _loc_1:* = TaskConfig.instance.getDialog(parseInt(this._taskInfo.stask.describe));
            if (_loc_1 != null)
            {
                this._txtDes.htmlText = _loc_1.talkStr;
            }
            else
            {
                this._txtDes.htmlText = Language.getString(21241);
            }
            var _loc_2:* = Cache.instance.task.getLinkTextData(this._taskInfo.stask.code);
            if (_loc_2 == null)
            {
                return;
            }
            if (_loc_2[this._taskInfo.curStep] != null)
            {
                this._link.setLinkText(_loc_2[this._taskInfo.curStep][0]);
                if (_loc_2[this._taskInfo.curStep][1] != null)
                {
                    if (this._link2 == null)
                    {
                        this._link2 = UICompomentPool.getUICompoment(GLinkText);
                        this._link2.x = this.sx;
                        this._link2.y = this._link.y + this._link.height + 2;
                        this._bodySprite.addChild(this._link2);
                        this._link2.widthConst = 194;
                    }
                    this._link2.setLinkText(_loc_2[this._taskInfo.curStep][1]);
                }
                else if (this._link2 != null)
                {
                    this._link2.dispose(true);
                    this._link2 = null;
                }
                if (_loc_2[this._taskInfo.curStep][2] != null)
                {
                    if (this._link3 == null)
                    {
                        this._link3 = UICompomentPool.getUICompoment(GLinkText);
                        this._link3.x = this.sx;
                        this._link3.y = this._link2.y + this._link2.height + 2;
                        this._bodySprite.addChild(this._link3);
                        this._link3.widthConst = 194;
                    }
                    this._link3.setLinkText(_loc_2[this._taskInfo.curStep][2]);
                }
                else if (this._link3 != null)
                {
                    this._link3.dispose(true);
                    this._link3 = null;
                }
            }
            this.updateChapterInfo(Cache.instance.task.chapterInfo);
            this.updateBtnLabel();
            return;
        }// end function

        private function removeGuideFlyBoot() : void
        {
            if (this._light != null)
            {
                this._light.dispose(true);
                this._light = null;
            }
            if (this._guideFlybootArrow != null)
            {
                this._guideFlybootArrow.dispose(true);
                this._guideFlybootArrow = null;
            }
            return;
        }// end function

        public function showGuideFlyBoot() : void
        {
            this.removeGuideFlyBoot();
            if (this._taskInfo.stask.guide != TaskGuideType.Guide_FlyBoot)
            {
                return;
            }
            var _loc_1:* = this._link.flyBoot;
            if (_loc_1 != null)
            {
                this._light = EffectManager.getTaskLightMask(28, 27);
                this._light.x = this._link.x + _loc_1.x - 2;
                this._light.y = this._link.y + _loc_1.y - 2;
            }
            this._bodySprite.addChild(this._light);
            EffectManager.glowFilterReg(this._light, [FilterConst.guideTaskFilter], 0.2, 7, 0);
            if (this._guideFlybootArrow == null)
            {
                this._guideFlybootArrow = UICompomentPool.getUICompoment(TaskGuideArrow) as TaskGuideArrow;
            }
            this._guideFlybootArrow.x = this._light.x + 13;
            this._guideFlybootArrow.y = this._light.y + 6;
            this._guideFlybootArrow.updateDatas(this._link.myData, true);
            this._bodySprite.addChild(this._guideFlybootArrow);
            this._link.clickHandler = this.removeGuideFlyBoot;
            return;
        }// end function

        private function updateBtnLabel() : void
        {
            if (this._btn == null || !this._resGot || this._taskInfo == null)
            {
                return;
            }
            if (this._taskInfo.isCanget())
            {
                this._btn.label = ImagesConst.taskLabel_LQRW;
            }
            else if (this._taskInfo.isComplete())
            {
                this._btn.label = ImagesConst.taskLabel_WCRW;
            }
            else
            {
                this._btn.label = ImagesConst.taskLabel_JXRW;
            }
            return;
        }// end function

        public function updateChapterInfo(param1:STaskChapter) : void
        {
            if (param1 == null || this._showingNum == param1.finishTaskNum)
            {
                return;
            }
            this._showingNum = param1.finishTaskNum;
            var _loc_2:* = TaskConfig.instance.getChapter(param1.finishTaskNum);
            var _loc_3:* = TaskConfig.instance.getToChapterNeedNum(_loc_2.id);
            var _loc_4:* = (param1.finishTaskNum - _loc_3) * 100 / _loc_2.taskNum;
            if (_loc_4 == 100)
            {
                this.clickRewardHandler(null);
                _loc_4 = 0;
                _loc_2 = TaskConfig.instance.getChapter((param1.finishTaskNum + 1));
            }
            var _loc_5:* = GameDefConfig.instance.getChineseNum((TaskConfig.instance.getChapterIndex(_loc_2) + 1));
            this._txtChapter.text = Language.getStringByParam(21242, _loc_5);
            this._txtJindu.text = _loc_4.toString() + "%";
            this._reward.itemData = this.getRewardItemData(_loc_2.reward);
            LoaderHelp.setBitmapdata("taskChapter_" + _loc_2.id.toString() + ".png", this._bmpChapter);
            return;
        }// end function

        private function getRewardItemData(param1:String) : ItemData
        {
            var _loc_4:ItemData = null;
            var _loc_2:* = param1.split("#");
            if (_loc_2.length == 0)
            {
                return new ItemData(parseInt(_loc_2[0]));
            }
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = new ItemData(parseInt(_loc_2[_loc_3]));
                if (ItemsUtil.isFitCarrer(_loc_4))
                {
                    return _loc_4;
                }
                _loc_3++;
            }
            return _loc_4;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bodySprite = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._bodySprite);
            this._bodySprite.mouseChildren = true;
            this._bodySprite.mouseEnabled = true;
            this.mouseChildren = true;
            this.mouseEnabled = true;
            this._bg = UIFactory.bg(0, 0, 254, 326, this._bodySprite, ImagesConst.TaskTrack_Bg);
            var _loc_1:* = GlobalStyle.textFormatAnjin;
            _loc_1.size = 16;
            _loc_1.bold = true;
            this._txtChapter = UIFactory.gTextField(Language.getString(21243), 104, 23, 140, 24, this._bodySprite, _loc_1);
            this._moveBtn = UIFactory.gLoadedButton(ImagesConst.TaskTrackMove_upSkin, this.sx, this.sy, 18, 18, this._bodySprite);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(20143), "#FFFFFF");
            this._btnShowTrack = new BtnShowTrackModule();
            this._btnShowTrack.width = 18;
            this._btnShowTrack.height = 18;
            this._btnShowTrack.x = this.sx + 184;
            this._btnShowTrack.y = this.sy;
            this.addChild(this._btnShowTrack);
            this._reward = UICompomentPool.getUICompoment(ShopSellItem);
            this._reward.x = this.sx + 6;
            this._reward.y = this.sy + 36;
            this._reward.setItemStyle(ItemStyleConst.Mid, ImagesConst.ShopItemBg, 6, 6);
            this._bodySprite.addChild(this._reward);
            this._bmpChapter = UIFactory.gImageBitmap(null, this.sx + 73, this.sy + 38, this._bodySprite);
            this._jindu = UIFactory.gBitmap(ImagesConst.TaskTrack_Drama, this.sx + 73, this.sy + 72, this._bodySprite);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._txtJindu = UIFactory.gTextField("", this.sx + 146, this.sy + 72, 120, 24, this._bodySprite, _loc_1);
            this._line = UIFactory.bg(this.sx, this.sy + 104, 200, 2, this._bodySprite, ImagesConst.SplitLine);
            this._txtName = UIFactory.gTextField("", this.sx, this._line.y + 6, 200, 22, this._bodySprite);
            this._txtName.textColor = 15848449;
            _loc_1 = GlobalStyle.textFormatAnjin;
            _loc_1.leading = 2;
            this._txtDes = UIFactory.gTextField("", this.sx, this._txtName.y + 18, 208, 100, this._bodySprite, _loc_1);
            this._txtDes.multiline = true;
            this._txtDes.wordWrap = true;
            this._link = UICompomentPool.getUICompoment(GLinkText);
            this._link.x = this.sx;
            this._link.y = this._txtDes.y + this._txtDes.textHeight + 6;
            this._bodySprite.addChild(this._link);
            this._link.widthConst = 194;
            this._btn = UIFactory.gLabelButton(null, GLabelButton.gLoadingButton, ResFileConst.TaskContinue, this.sx + 55, this._link.y + this._link.height + 2, 103, 40, this._bodySprite);
            this._moveBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this._btnShowTrack.configEventListener(MouseEvent.CLICK, this.showHideTrackHandler);
            this._btn.configEventListener(MouseEvent.CLICK, this.linkHandler);
            LoaderHelp.addResCallBack(ResFileConst.taskLabels, this.resGotHandler);
            this._reward.configEventListener(MouseEvent.CLICK, this.clickRewardHandler);
            return;
        }// end function

        private function clickRewardHandler(event:MouseEvent) : void
        {
            if (this._reward != null && this._reward.bitmapdata != null)
            {
                FlyToNavbarTool.flyBitmapOriginalToPack(this._reward.bitmapdata, this._reward.localToGlobal(GameConst.yellowPoint));
            }
            if (this._taskInfo != null)
            {
                this.updateLayout();
                this.showGuideFlyBoot();
            }
            return;
        }// end function

        public function updateLayout() : void
        {
            var _loc_2:int = 0;
            var _loc_3:GLinkText = null;
            this._txtName.y = this._line.y + 6;
            this._txtDes.y = this._txtName.y + 18;
            this._link.y = this._txtDes.y + this._txtDes.textHeight + 4;
            this._btn.y = this._link.y + this._link.height + 8;
            if (this._link2 != null)
            {
                this._link2.y = this._link.y + this._link.height + 3;
                this._btn.y = this._link2.y + this._link2.height + 8;
            }
            if (this._link3 != null)
            {
                this._link3.y = this._link2.y + this._link2.height + 3;
                this._btn.y = this._link3.y + this._link3.height + 8;
            }
            var _loc_1:int = 0;
            if (this._subLines != null && this._subLines.length > 0)
            {
                if (this._line2 == null)
                {
                    this._line2 = UIFactory.bg(this.sx, this._btn.y + 42, 200, 2, this._bodySprite, ImagesConst.SplitLine);
                }
                this._line2.y = this._btn.y + 42;
                _loc_1 = this._line2.y + 6;
                _loc_2 = 0;
                while (_loc_2 < this._subLines.length)
                {
                    
                    _loc_3 = this._subLines[_loc_2];
                    _loc_3.x = this.sx;
                    _loc_3.y = _loc_1;
                    _loc_1 = _loc_1 + _loc_3.height + 2;
                    _loc_2++;
                }
                this._bg.height = _loc_1 + 20;
            }
            else
            {
                if (this._line2 != null)
                {
                    this._line2.dispose(true);
                    this._line2 = null;
                }
                this._bg.height = this._btn.y + 55;
            }
            return;
        }// end function

        private function resGotHandler() : void
        {
            this._resGot = true;
            this.updateBtnLabel();
            return;
        }// end function

        private function linkHandler(event:MouseEvent) : void
        {
            if (this._link != null)
            {
                this._link.linkImpl("");
            }
            return;
        }// end function

        private function showHideTrackHandler(event:MouseEvent) : void
        {
            this._bodySprite.visible = !this._btnShowTrack.isClose;
            return;
        }// end function

        private function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            this._dragRect.x = 0;
            this._dragRect.y = 0;
            this._dragRect.width = SceneRange.display.width - 30;
            this._dragRect.height = SceneRange.display.height - 30;
            startDrag(false, this._dragRect);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function onStageMouseUpHandler(event:MouseEvent) : void
        {
            stopDrag();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - 238;
            y = 160;
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.stageResize();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._taskInfo = null;
            this._txtChapter.dispose(param1);
            this._txtChapter = null;
            this._bodySprite.dispose(param1);
            this._bodySprite = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._moveBtn.dispose(param1);
            this._moveBtn = null;
            this._btnShowTrack.dispose(param1);
            this._btnShowTrack = null;
            this._bmpChapter.dispose(param1);
            this._bmpChapter = null;
            this._jindu.dispose(param1);
            this._jindu = null;
            this._txtJindu.dispose(param1);
            this._txtJindu = null;
            this._line.dispose(param1);
            this._line = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtDes.dispose(param1);
            this._txtDes = null;
            this._link.dispose(param1);
            this._link = null;
            if (this._link2 != null)
            {
                this._link2.dispose(param1);
                this._link2 = null;
            }
            if (this._link3 != null)
            {
                this._link3.dispose(param1);
                this._link3 = null;
            }
            this._btn.dispose(param1);
            this._btn = null;
            this._reward.dispose(param1);
            this._reward = null;
            this.removeGuideFlyBoot();
            if (this._subLines != null)
            {
                DisplayUtil.delNotUse(this._subLines, 0);
            }
            this._subLines = [];
            return;
        }// end function

    }
}
